package cn.dengta.webapp.im.entity;

import java.util.Date;

import cn.dengta.common.model.BizFlag;
import cn.dengta.common.model.Status;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 用户搭讪记录表
 *
 * @author Ready
 * @since 2022-04-19
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("im_greet_log")
public class GreetLog extends TimeBasedEntity implements BizFlag.WritableBizFlag {

	private static final long serialVersionUID = 1L;
	/** 标识：是否来自推荐 */
	public static final long FLAG_FROM_RECOMMEND = 1L;
	/** 标识：是否来自牵线 */
	public static final long FLAG_USER_PULL_WIRE = 1L << 1;

	/** ID较小的用户ID */
	private Long lowUserId;
	/** ID较大的用户ID */
	private Long highUserId;
	/** 发起搭讪的用户ID */
	private Long fromUserId;
	/** 状态：0=未回复；1=已回复 */
	private Integer status;
	/** 搭讪记录ID */
	private Long greetTextId;
	/** 业务标识 */
	private long bizFlag;

	public GreetLog init(Long lowUserId, Long highUserId, Long fromUserId, Long greetTextId, Date now, boolean fromRecommend, boolean pullWire) {
		this.lowUserId = lowUserId;
		this.highUserId = highUserId;
		this.fromUserId = fromUserId;
		this.status = Status.NO.value;
		this.greetTextId = greetTextId;
		if (fromRecommend) {
			addFlag(FLAG_FROM_RECOMMEND);
		}
		if (pullWire) {
			addFlag(FLAG_USER_PULL_WIRE);
		}
		this.initTime(now);
		return this;
	}

	@Override
	public void setBizFlag(long flag) {
		this.bizFlag = flag;
	}

	public static final String LOW_USER_ID = "low_user_id";
	public static final String HIGH_USER_ID = "high_user_id";
	public static final String FROM_USER_ID = "from_user_id";
	public static final String GREET_TEXT_ID = "greet_text_id";
	public static final String STATUS = "status";

}
